//
//  DiscountCell.m
//  MyTrip
//
//  Created by zhang on 15/8/27.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "DiscountCell.h"
#import "UIImageView+WebCache.h"

@implementation DiscountCell

- (void)dealloc
{
    [_moneyLabel release];
    [_timeLabel release];
    [_titleLabel release];
    [_timeImage release];
    [_picImage release];
    [super dealloc];
}


- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.picImage = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height / 2 - 10 * OffHeight)] autorelease];
        [self.contentView addSubview:_picImage];
        
        self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5 * OffWidth, _picImage.frame.size.height + _picImage.frame.origin.y + 5 * OffHeight, frame.size.width, 55 * OffHeight)] autorelease];
        [self.contentView addSubview:_titleLabel];
        
        
        self.timeImage = [[[UIImageView alloc] initWithFrame:CGRectMake(5 * OffWidth, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, 15 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_timeImage];
        
        
        self.timeLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_timeImage.frame.size.width + _timeImage.frame.origin.x, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, frame.size.width - 18 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_timeLabel];
        
        
        self.moneyLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5 * OffWidth, _timeLabel.frame.size.height + _timeLabel.frame.origin.y + 15 * OffHeight, 120 * OffWidth, 20 * OffHeight)] autorelease];
        [self.contentView addSubview:_moneyLabel];
        
    }
    return self;
}


- (void)setValueForCellWithDic:(NSDictionary *)dic{
    
    [_picImage sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"pic"]] placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]
     ];
    
    [_titleLabel setText:[dic objectForKey:@"title"]];
    _titleLabel.font = [UIFont systemFontOfSize:16];
    _titleLabel.numberOfLines = 2;
    
    [_timeLabel setText:[dic objectForKey:@"departureTime"]];
    _timeLabel.font = [UIFont systemFontOfSize:14];
    _timeLabel.alpha = 0.5;
    
    [_timeImage setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"time" ofType:@"png"]]];
    
    NSString *money = [dic objectForKey:@"price"];
    money = [money stringByReplacingOccurrencesOfString:@"<em>" withString:@""];
    money = [money stringByReplacingOccurrencesOfString:@"</em>" withString:@""];
    
    NSRange r = [money rangeOfString:@"元起"];
    NSRange aR = [money rangeOfString:money];
    NSRange nR = NSMakeRange(aR.location, aR.length - r.length);
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:money];
    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} range:r];
    [string addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10]} range:r];
    
    [string addAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} range:nR];
    [string addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} range:nR];
    
    [_moneyLabel setAttributedText:string];
    
}





@end
